package com.lin.missyou.service;

import com.lin.missyou.model.Spu;
import com.lin.missyou.repository.SpuRepository;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

@Service
public class SearchService {

    @Autowired
    private SpuRepository spuRepository;

    public Page<Spu> search(String q, Integer page, Integer size){
        Pageable pageable = PageRequest.of(page, size, Sort.by("createTime").descending());
        String keysWord = "%"+q+"%";
        return this.spuRepository.findByTitleIsLikeOrSubtitleLike(keysWord, keysWord, pageable);

    }
}
